import re
import requests
import time
from multiprocessing import Pool

def get_reply(url):
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'
    }

    # 发送请求
    request = requests.get(url=url, headers=headers)
    request.encoding='gbk'
    # 返回html源代码
    html = request.text
    return html

def parse_reply(html,name):
    # 小说的主体内容
    content = re.compile(r'(.*?)<br />')
    contents = re.findall(content, str(html))
    with open("./球状闪电/" + name + ".txt", 'a', encoding="utf-8") as f:
        for i in range(len(contents)):
            contents[i] = contents[i].strip()
            f.write(contents[i])

def main():
    for i in range(116007,116009):
        url = f"https://www.kanunu8.com/book3/6633/" + str(i) + ".html"
        html = get_reply(url)
        name = "第" + str(i - 116006) + "章"
        parse_reply(html,name)
    time.sleep(1)

if __name__ == '__main__':
    main()
    print("ok")